package com.web.common.dataDictionary.PO;

import java.util.*;
import com.css.sword.kernel.base.annotation.*;
import com.css.sword.kernel.base.dataElement.*;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;

import com.web.common.dataDictionary.DE.DE_ID;
import com.web.common.dataDictionary.DE.DE_CATEGORYID;
import com.web.common.dataDictionary.DE.DE_CATEGORYNAME;
import com.web.common.dataDictionary.DE.DE_GOODSNAME;
import com.web.common.dataDictionary.DE.DE_GOODSPRICE;
import com.web.common.dataDictionary.DE.DE_REALVALUE;
import com.web.common.dataDictionary.DE.DE_OPPTIME;
import com.web.common.dataDictionary.DE.DE_BZ;


/**
 * 商品表; InnoDB free: 10240 kB
 */
@PersistObject
public class TabGoodsPO extends AbsPersistObject {
	//private static final long serialVersionUID = -3212531855007207019L;
	private static final long serialVersionUID = 1L;
	private static final Map<String, Integer> fieldIndex = new HashMap<String, Integer>(8);
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(8);
	
	static{
		fieldIndex.put("id",0);fieldIndex.put("categoryid",1);fieldIndex.put("categoryname",2);fieldIndex.put("goodsname",3);fieldIndex.put("goodsprice",4);fieldIndex.put("realvalue",5);fieldIndex.put("opptime",6);fieldIndex.put("bz",7);
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "tab_goods";

	/**
	 * id
	 */
	private DE_ID id = DE_ID.getTemplateInstance();

	/**
	 * 商品分类id
	 */
	private DE_CATEGORYID categoryid = DE_CATEGORYID.getTemplateInstance();

	/**
	 * 商品分类名称
	 */
	private DE_CATEGORYNAME categoryname = DE_CATEGORYNAME.getTemplateInstance();

	/**
	 * 商品名称
	 */
	private DE_GOODSNAME goodsname = DE_GOODSNAME.getTemplateInstance();

	/**
	 * 商品价格
	 */
	private DE_GOODSPRICE goodsprice = DE_GOODSPRICE.getTemplateInstance();

	/**
	 * 真实的值
	 */
	private DE_REALVALUE realvalue = DE_REALVALUE.getTemplateInstance();

	/**
	 * 操作时间
	 */
	private DE_OPPTIME opptime = DE_OPPTIME.getTemplateInstance();

	/**
	 * 商品备注
	 */
	private DE_BZ bz = DE_BZ.getTemplateInstance();


	public TabGoodsPO(){
		this.insertState = new BitSet(8);
		this.updateState = new BitSet(8);
	}

	
	/**
	 * 获取 "id" 值
	 */	
	public DE_ID getId(){
		return  id;
	}
	
	/**
	 * 设置 "id" 值
	 */
	public void setId(DE_ID id) {
		if(id == null){
			id= DE_ID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.id = id;
	}
	
	/**
	 * 获取 "商品分类id" 值
	 */	
	public DE_CATEGORYID getCategoryid(){
		return  categoryid;
	}
	
	/**
	 * 设置 "商品分类id" 值
	 */
	public void setCategoryid(DE_CATEGORYID categoryid) {
		if(categoryid == null){
			categoryid= DE_CATEGORYID.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.categoryid = categoryid;
	}
	
	/**
	 * 获取 "商品分类名称" 值
	 */	
	public DE_CATEGORYNAME getCategoryname(){
		return  categoryname;
	}
	
	/**
	 * 设置 "商品分类名称" 值
	 */
	public void setCategoryname(DE_CATEGORYNAME categoryname) {
		if(categoryname == null){
			categoryname= DE_CATEGORYNAME.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.categoryname = categoryname;
	}
	
	/**
	 * 获取 "商品名称" 值
	 */	
	public DE_GOODSNAME getGoodsname(){
		return  goodsname;
	}
	
	/**
	 * 设置 "商品名称" 值
	 */
	public void setGoodsname(DE_GOODSNAME goodsname) {
		if(goodsname == null){
			goodsname= DE_GOODSNAME.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.goodsname = goodsname;
	}
	
	/**
	 * 获取 "商品价格" 值
	 */	
	public DE_GOODSPRICE getGoodsprice(){
		return  goodsprice;
	}
	
	/**
	 * 设置 "商品价格" 值
	 */
	public void setGoodsprice(DE_GOODSPRICE goodsprice) {
		if(goodsprice == null){
			goodsprice= DE_GOODSPRICE.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.goodsprice = goodsprice;
	}
	
	/**
	 * 获取 "真实的值" 值
	 */	
	public DE_REALVALUE getRealvalue(){
		return  realvalue;
	}
	
	/**
	 * 设置 "真实的值" 值
	 */
	public void setRealvalue(DE_REALVALUE realvalue) {
		if(realvalue == null){
			realvalue= DE_REALVALUE.getTemplateInstance();
		}
		recordChangeFlag(5);
		this.realvalue = realvalue;
	}
	
	/**
	 * 获取 "操作时间" 值
	 */	
	public DE_OPPTIME getOpptime(){
		return  opptime;
	}
	
	/**
	 * 设置 "操作时间" 值
	 */
	public void setOpptime(DE_OPPTIME opptime) {
		if(opptime == null){
			opptime= DE_OPPTIME.getTemplateInstance();
		}
		recordChangeFlag(6);
		this.opptime = opptime;
	}
	
	/**
	 * 获取 "商品备注" 值
	 */	
	public DE_BZ getBz(){
		return  bz;
	}
	
	/**
	 * 设置 "商品备注" 值
	 */
	public void setBz(DE_BZ bz) {
		if(bz == null){
			bz= DE_BZ.getTemplateInstance();
		}
		recordChangeFlag(7);
		this.bz = bz;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {id,categoryid,categoryname,goodsname,goodsprice,realvalue,opptime,bz};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"id","categoryid","categoryname","goodsname","goodsprice","realvalue","opptime","bz"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
		switch (index) {
		case 0 : return id;
		case 1 : return categoryid;
		case 2 : return categoryname;
		case 3 : return goodsname;
		case 4 : return goodsprice;
		case 5 : return realvalue;
		case 6 : return opptime;
		case 7 : return bz;
 
		default:
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
	}
	
	@Override
	public TabGoodsPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}

		switch (index) {

				case 0 : {
					if (fieldValue == null) {
						setId(null);
					} else {
						setId((DE_ID) fieldValue);
					}
					return this;
				}
				
				case 1 : {
					if (fieldValue == null) {
						setCategoryid(null);
					} else {
						setCategoryid((DE_CATEGORYID) fieldValue);
					}
					return this;
				}
				
				case 2 : {
					if (fieldValue == null) {
						setCategoryname(null);
					} else {
						setCategoryname((DE_CATEGORYNAME) fieldValue);
					}
					return this;
				}
				
				case 3 : {
					if (fieldValue == null) {
						setGoodsname(null);
					} else {
						setGoodsname((DE_GOODSNAME) fieldValue);
					}
					return this;
				}
				
				case 4 : {
					if (fieldValue == null) {
						setGoodsprice(null);
					} else {
						setGoodsprice((DE_GOODSPRICE) fieldValue);
					}
					return this;
				}
				
				case 5 : {
					if (fieldValue == null) {
						setRealvalue(null);
					} else {
						setRealvalue((DE_REALVALUE) fieldValue);
					}
					return this;
				}
				
				case 6 : {
					if (fieldValue == null) {
						setOpptime(null);
					} else {
						setOpptime((DE_OPPTIME) fieldValue);
					}
					return this;
				}
				
				case 7 : {
					if (fieldValue == null) {
						setBz(null);
					} else {
						setBz((DE_BZ) fieldValue);
					}
					return this;
				}
				
		default:
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}
	
	}

	@Override
	protected TabGoodsPO clone() {
		TabGoodsPO t = new TabGoodsPO();
		
		t.setId(this.id);
		t.setCategoryid(this.categoryid);
		t.setCategoryname(this.categoryname);
		t.setGoodsname(this.goodsname);
		t.setGoodsprice(this.goodsprice);
		t.setRealvalue(this.realvalue);
		t.setOpptime(this.opptime);
		t.setBz(this.bz);

		return t;
	}

	@Override
	public TabGoodsPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("id")){
			value = dataMap.get("id");
			
			if (value == null) {
				this.setId(null);
			} else {
				if (value instanceof DE_ID) {
					this.setId((DE_ID) value);
				}
			    else {
					this.setId(new DE_ID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("categoryid")){
			value = dataMap.get("categoryid");
			
			if (value == null) {
				this.setCategoryid(null);
			} else {
				if (value instanceof DE_CATEGORYID) {
					this.setCategoryid((DE_CATEGORYID) value);
				}
			    else {
					this.setCategoryid(new DE_CATEGORYID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("categoryname")){
			value = dataMap.get("categoryname");
			
			if (value == null) {
				this.setCategoryname(null);
			} else {
				if (value instanceof DE_CATEGORYNAME) {
					this.setCategoryname((DE_CATEGORYNAME) value);
				}
			    else {
					this.setCategoryname(new DE_CATEGORYNAME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("goodsname")){
			value = dataMap.get("goodsname");
			
			if (value == null) {
				this.setGoodsname(null);
			} else {
				if (value instanceof DE_GOODSNAME) {
					this.setGoodsname((DE_GOODSNAME) value);
				}
			    else {
					this.setGoodsname(new DE_GOODSNAME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("goodsprice")){
			value = dataMap.get("goodsprice");
			
			if (value == null) {
				this.setGoodsprice(null);
			} else {
				if (value instanceof DE_GOODSPRICE) {
					this.setGoodsprice((DE_GOODSPRICE) value);
				}
			    else {
					this.setGoodsprice(new DE_GOODSPRICE(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("realvalue")){
			value = dataMap.get("realvalue");
			
			if (value == null) {
				this.setRealvalue(null);
			} else {
				if (value instanceof DE_REALVALUE) {
					this.setRealvalue((DE_REALVALUE) value);
				}
			    else {
					this.setRealvalue(new DE_REALVALUE(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("opptime")){
			value = dataMap.get("opptime");
			
			if (value == null) {
				this.setOpptime(null);
			} else {
				if (value instanceof DE_OPPTIME) {
					this.setOpptime((DE_OPPTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setOpptime(new DE_OPPTIME((java.util.Date)value));
				}
			    else {
					this.setOpptime(new DE_OPPTIME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("bz")){
			value = dataMap.get("bz");
			
			if (value == null) {
				this.setBz(null);
			} else {
				if (value instanceof DE_BZ) {
					this.setBz((DE_BZ) value);
				}
			    else {
					this.setBz(new DE_BZ(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("id", id);
		dataMap.put("categoryid", categoryid);
		dataMap.put("categoryname", categoryname);
		dataMap.put("goodsname", goodsname);
		dataMap.put("goodsprice", goodsprice);
		dataMap.put("realvalue", realvalue);
		dataMap.put("opptime", opptime);
		dataMap.put("bz", bz);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("id", (id==null?null:id.value));
		dataMap.put("categoryid", (categoryid==null?null:categoryid.value));
		dataMap.put("categoryname", (categoryname==null?null:categoryname.value));
		dataMap.put("goodsname", (goodsname==null?null:goodsname.value));
		dataMap.put("goodsprice", (goodsprice==null?null:goodsprice.value));
		dataMap.put("realvalue", (realvalue==null?null:realvalue.value));
		dataMap.put("opptime", (opptime==null?null:opptime.value));
		dataMap.put("bz", (bz==null?null:bz.value));
		
		return dataMap;
	}
	
	@Override
	public TabGoodsPO newInstance() {
		return new TabGoodsPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{id};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (id.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段id不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && id.value == null) {
			errorMsg.append("字段id不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("id:").append(id.value!=null?id:"").append(" ").append("categoryid:").append(categoryid.value!=null?categoryid:"").append(" ").append("categoryname:").append(categoryname.value!=null?categoryname:"").append(" ").append("goodsname:").append(goodsname.value!=null?goodsname:"").append(" ").append("goodsprice:").append(goodsprice.value!=null?goodsprice:"").append(" ").append("realvalue:").append(realvalue.value!=null?realvalue:"").append(" ").append("opptime:").append(opptime.value!=null?opptime:"").append(" ").append("bz:").append(bz.value!=null?bz:"").append(" ");
		return str.toString();
	}
	
}
